package com.tiankun.eurekaswagger.controller;


import com.tiankun.eurekaswagger.proxy.UserHanlder;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * User: bear
 * Date: 2020/11/11
 * Description
 * Version: V1.0
 */
@Api(value = "用户", tags = "用户接口API")
@ApiResponses({
        @ApiResponse(code = 400, message = "请求参数不完整或者错误"),
        @ApiResponse(code = 404, message = "找不到页面"),
        @ApiResponse(code = 406, message = "页面地址和接口名冲突"),
        @ApiResponse(code = 415, message = "请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code = 500, message = "后台服务错误")
})
@RequestMapping("user")
@CrossOrigin   //用于实现跨域的注解
@RestController
public class UserController {

    @Resource
    UserHanlder userHanlder;

    @RequestMapping(value = "getList",method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @ApiOperation(value = "获取用户列表接口", notes = "获取用户列表接口", httpMethod = "post")
    public Map getList(){
        Map<String,Object> map =new HashMap<>();
        map.put("code","200");
        Map<String,Object> user=new HashMap<>();
        user.put("id",1);
        user.put("name","测试名");
        user.put("phone","11011011011");
        user.put("img","一个图片的地址，通过地址可以显示图片");
        map.put("data",user);
        map.put("msg","用户信息");
        return map;
    }

    @ResponseBody
    @PostMapping("testParam")
    @ApiOperation(value = "测试传参格式接口",notes = "测试传参格式接口",httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "ID",paramType = "query",dataType = "Integer",required = true),
            @ApiImplicitParam(name = "name",value = "名字",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "phone",value = "号码",paramType = "query",dataType = "String",required = true)
    })
    public Map testParam(@RequestParam("id") Integer id,@RequestParam("name") String name,@RequestParam("name") String phone){
        Map<String,Object> map =new HashMap<>();
        Map<String,Object> param =new HashMap<>();
        param.put("id",id);
        param.put("name",name);
        param.put("phone",phone);
        param.put("idType",id.getClass());
        param.put("nameType",name.getClass());
        param.put("phoneType",phone.getClass());
        map.put("code","200");
        map.put("msg","传参正确");
        map.put("data",param);
        return map;
    }

    @PostMapping("testBody")
    @ResponseBody
    @ApiOperation(value = "测试json传参格式接口",notes = "测试json传参格式接口",httpMethod = "post")
    public Map testParam(@RequestBody @ApiParam(name = "user", value = "userBean", required = true)Map map){
        Map<String,Object> map1 =new HashMap<>();
        map1.put("code","200");
        map1.put("data",map);
        map1.put("msg","传参成功");
        return map;
    }



}
